qclearWd <- function(workDir, tag){
  if( is.null(tag) ){
      unlink(file.path(workDir, "err"), recursive=TRUE)
      unlink(file.path(workDir, "log"), recursive=TRUE)
      unlink(file.path(workDir, "out"), recursive=TRUE)
      unlink(file.path(workDir, paste(tag, "-common.Rdata", sep="")))      
    }else{
      unlink(file.path(workDir, "err", tag), recursive=TRUE)
      unlink(file.path(workDir, "log", tag), recursive=TRUE)
      unlink(file.path(workDir, "out", tag), recursive=TRUE)
      unlink(file.path(workDir, paste("*-common.Rdata", sep="")))
      if( length(list.files(file.path(workDir, "err")))==0 ) unlink(file.path(workDir, "err"),recursive=TRUE)
      if( length(list.files(file.path(workDir, "log")))==0 ) unlink(file.path(workDir, "log"),recursive=TRUE)
      if( length(list.files(file.path(workDir, "out")))==0 ) unlink(file.path(workDir, "out"),recursive=TRUE)
    }
  unlink(file.path(workDir, "qcontrol.R"))
}
